package edu.cug.water.crawler.job.request;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

@Component
public class RequestUtil {

    @Autowired
    RestTemplate simpleRestTemplate;


    public ResponseEntity<String> request(String url, HttpMethod requestMethod, HttpEntity httpEntity){
        return simpleRestTemplate.exchange(url, requestMethod, httpEntity, String.class);
    }

    public ResponseEntity<String> get(String url, HttpHeaders headers){
        HttpEntity<Object> httpEntity = new HttpEntity<>(null, headers);
        return simpleRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
    }

    public ResponseEntity<String> post(String url, HttpHeaders headers, MultiValueMap params){
        HttpEntity<MultiValueMap> httpEntity = new HttpEntity<>(params, headers);
        return simpleRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
    }



}
